package sh.grapendaal.tsuushin.module.uno.engine.event.dispatcher;

import sh.grapendaal.tsuushin.module.uno.engine.domain.Playable;
import sh.grapendaal.tsuushin.module.uno.engine.domain.Player;
import sh.grapendaal.tsuushin.module.uno.engine.event.CommandEvent;
import sh.grapendaal.tsuushin.module.uno.engine.event.CommandEvent.Type;
import sh.grapendaal.tsuushin.module.uno.engine.event.listener.EventListener;

public abstract class CommandEventDispatcher extends EventDispatcher<CommandEvent> {
	public void dispatchPlayerJoin(final Player player) {
		dispatchEvent(new EventRunnable<CommandEvent>() {
			@Override
			public void run(EventListener<CommandEvent> listener) {
				listener.onPlayerJoin(new CommandEvent(Type.JOIN, player));
			}
		});
	}

	public void dispatchPlayerLeave(final Player player) {
		dispatchEvent(new EventRunnable<CommandEvent>() {
			@Override
			public void run(EventListener<CommandEvent> listener) {
				listener.onPlayerLeave(new CommandEvent(Type.LEAVE, player));
			}
		});
	}

	public void dispatchGameStart(final Player firstPlayer) {
		dispatchEvent(new EventRunnable<CommandEvent>() {
			@Override
			public void run(EventListener<CommandEvent> listener) {
				listener.onGameStart(new CommandEvent(Type.START, firstPlayer));
			}
		});
	}

	public void dispatchGameStop(final Player firstPlayer) {
		dispatchEvent(new EventRunnable<CommandEvent>() {
			@Override
			public void run(EventListener<CommandEvent> listener) {
				listener.onGameStop(new CommandEvent(Type.STOP, firstPlayer));
			}
		});
	}

	public void dispatchCardPlay(final Player player, final Playable input) {
		dispatchEvent(new EventRunnable<CommandEvent>() {
			@Override
			public void run(EventListener<CommandEvent> listener) {
				listener.onCardPlay(new CommandEvent(Type.PLAY, player, input));
			}
		});
	}

	public void dispatchCardDraw(final Player player) {
		dispatchEvent(new EventRunnable<CommandEvent>() {
			@Override
			public void run(EventListener<CommandEvent> listener) {
				listener.onCardDraw(new CommandEvent(Type.DRAW, player));
			}
		});
	}

	public void dispatchCardPass(final Player player) {
		dispatchEvent(new EventRunnable<CommandEvent>() {
			@Override
			public void run(EventListener<CommandEvent> listener) {
				listener.onCardPass(new CommandEvent(Type.PASS, player));
			}
		});
	}
}
